// js typeof
function printId(id: number | string) {
    if (typeof id === "string") {
        console.log(id.split(" "));
        return
    }
    console.log(id + id);
}

// 2.方向的类型判断  平等判断
type Diection = "left" | "right" | "up" | "down"

function switchDirection(diection: Diection) {
    if (diection === "left") {
        console.log('left');
    } else if (diection === "right") {
        console.log('right');
    } else if (diection === "up") {
        console.log('up');
    }
    console.log(
        'down'
    );

}

// instanceof
function printDate(date: string | Date) {
    if (date instanceof Date) {
        console.log(date.getTime());
        return
    }
    console.log(date.split(""));
}

// in 判断是否有一个属性
interface ISwim {
    swim: () => void
}

interface IRun {
    run: () => void
}

function move(animal: ISwim | IRun) {
    if ("swim" in animal) {
        animal.swim()
    } else {
        animal.run()
    }
}

export { }